/**
 * $RCSfile$
 * $Revision$
 * $Date$
 * $Source$
 * $Author$
 */
package pl.edu.agh.loganalizator.view;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;

import pl.edu.agh.loganalizator.model.PairRule;
import pl.edu.agh.loganalizator.model.Rule;

public class RuleSetter extends JPanel implements ActionListener {
  JTextField iJTextField;
  JTextField iJTextField1;
  JButton button;
  Rule rule;
  AddRuleDialogFrame addRuleDialogFrame;

  public RuleSetter(Rule rule, AddRuleDialogFrame addRuleDialogFrame) {
    super(new BorderLayout());
    this.addRuleDialogFrame = addRuleDialogFrame;
    this.rule = rule;
    button = new JButton("Ustaw wartość");

    iJTextField = new JTextField(10);
    if (rule instanceof PairRule) {
      iJTextField1 = new JTextField(10);
      add(iJTextField1, BorderLayout.CENTER);
      add(iJTextField, BorderLayout.WEST);
    }
    else {
      add(iJTextField, BorderLayout.CENTER);
    }

    add(button, BorderLayout.AFTER_LINE_ENDS);
    this.setVisible(true);
    button.addActionListener(this);
    repaint();
  }

  @Override
  public void actionPerformed(ActionEvent arg0) {
    rule.setVelue(iJTextField.getText());
    if (rule instanceof PairRule) {
      rule.setVelue(iJTextField1.getText());
    }
    addRuleDialogFrame.setRule(rule);
  }
}
